#include "FileSendThread.h"

FileSendThread::FileSendThread()
{
}

FileSendThread::FileSendThread(QSerialPort* serial, QFile* file, QProgressBar* progress)
{
	p_serial = serial;
	file_to_send = file;
	p_progress = progress;
}

void FileSendThread::run()
{
	if (!file_to_send->open(QIODevice::ReadOnly)) {
		LoggerSingleton::getInstance().debug("file open fail in FILE_SEND_THREAD");
		return;
	}
	int buff_size = 128;
	QByteArray array;
	qint64 file_size = file_to_send->size();
	//p_progress->setRange(0, file_size);
	qint64 have_send_size = 0;
	while (true) {
		array = file_to_send->read(buff_size);
		if (array.isEmpty()) {
			break;
		}
		p_serial->write(array);
		have_send_size += array.size();
		//p_progress->setValue(have_send_size);
	}
	file_to_send->close();
}
